<!--GPS已安装-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="car-label">关键字:</div>
      <el-input v-model="listQuery.title" placeholder="Title" style="width: 130px;" class="filter-item" />
      <div class="car-label">安装时间:</div>
      <el-date-picker v-model="listQuery.importance" placeholder="请选择提交时间" clearable style="width: 130px" class="filter-item" />
      <div class="car-label">设备状态:</div>
      <el-select v-model="listQuery.type" placeholder="Type" clearable class="filter-item" style="width: 130px">
        <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name+'('+item.key+')'" :value="item.key" />
      </el-select>
      <div class="car-label">审核时间:</div>
      <el-date-picker v-model="listQuery.importance" placeholder="请选择提交时间" clearable style="width: 130px" class="filter-item" />
      <el-button v-waves style="margin-left: 10px" class="filter-item" type="primary" icon="el-icon-search">
        搜索
      </el-button>
      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" @click="handleDownload">
        审核
      </el-button>
      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" @click="handleDownload">
        作废
      </el-button>
      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" @click="handleDownload">
        拆除
      </el-button>
      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" @click="handleDownload">
        导出
      </el-button>
    </div>
    <ve-table
      style="width:100%"
      :columns="columns"
      :table-data="tableData"
      :border-x="true"
      row-key-field-name="id"
      :border-y="true"
      :row-style-option="rowStyleOption"
      :checkbox-option="checkboxOptipon"
    />
    <div class="table-pagination">
      <ve-pagination
        :total="totalCount"
        :page-index="pageIndex"
        :page-size="pageSize"
        @on-page-number-change="pageNumberChange"
        @on-page-size-change="pageSizeChange"
      />
    </div>
    <el-dialog
      class="lnk-dialog"
      :close-on-click-modal="false"
      :title="dialogTitle"
      top="10vh"
      width="80%"
      :visible.sync="newDialog"
      :append-to-body="true"
    >
      <GpsDetail :gpsOrderId="gpsOrderId" @canceldialog="canceldialog" :installGps="false"></GpsDetail>
    </el-dialog>
  </div>
</template>

<style>
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .gps-image{
    min-height: 200px;
    border: 1px dashed lightgray;
  }
  .gps-image-item{
    display: inline-block !important;
    margin: 5px;
  }
  .el-image{
    width: 100px;
    height: 100px;
  }
</style>

<script>
import GpsDetail from "./gps-detail"
export default {
  components: {GpsDetail},
  data() {
    return {
      // page index
      pageIndex: 1,
      dataTable: [],
      newDialog:false,
      totalCount: '',
      // page size
      pageSize: 10,
      listQuery: {},
      gpsOrderId:"",//选中的GPS工单号id
      rowStyleOption: {
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      checkboxOptipon: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          console.log(row, isSelected, selectedRowKeys);
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      columns: [
        {
          field: '',
          key: '1',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: '',
          key: 'a',
          title: '序号',
          align: 'center',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (this.pageIndex - 1) * this.pageSize + rowIndex + 1
          }
        },
        { field: 'orderId', key: 'b', title: '订单编号', align: 'center', width: '150px',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (
              <span class={'id-column'} on-click={() => this.gotoDetail(row.id,row.status)}>{row.orderId}</span>)
          } },
        { field: 'orderId', key: 'c', title: 'GPS订单号', align: 'center', width: '150px',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            console.log(row)
            return (
              <span class={'id-column'} on-click={() => this.showGpsDetail(row.id)}>{row.orderId}</span>)
          } },
        { field: 'hobby', key: 'd', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'address', key: 'e', title: '贷款金额', width: '100px' },
        { field: 'address', key: 'g', title: '部门', width: '' },
        { field: 'address', key: 'h', title: '业务员', width: '100px' },
        { field: 'address', key: 'i', title: '序列号', width: '100px' },
        { field: 'address', key: 'j', title: '安装时间', width: '100px' },
        { field: 'address', key: 'k', title: '审核人', width: '180px' },
        { field: 'address', key: 'l', title: '审核时间', width: '180px' },
        { field: 'address', key: 'm', title: '设备状态', width: '180px' }
      ]
    }
  },
  computed: {
  },
  created() {
    this.initDatabase()
  },
  methods: {
    // page number change
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
    },

    // page size change
    pageSizeChange(pageSize) {
      this.pageIndex = 1
      this.pageSize = pageSize
    },

    // Simulation table data
    async initDatabase() {
      this.tableData = []
      this.listQuery.appid = this.appId
      const data = await this.$http.post('/flow/orders/list/' + this.pageIndex + '/' + this.pageSize, this.listQuery)
      if (data.code === 200) {
        data.data.records.map((item, index) => {
          return item.rowKey = index
        })
        this.tableData = data.data.records
        this.totalCount = data.data.total
      }
    },
    /*
    跳转Order详情页面
    */
    gotoDetail(id,status) {
      if(status == "待提交") {
        this.$router.push({ path: '/a-content/customer-reference/add-bussiness', query: { id: id, source: 'orderList' }})
      } else if(status == "待征信查询"){
        this.$router.push({ path: '/a-content/customer-reference/bank-refer-detail', query: { id: id, source: 'referenceList' }})

      } else if(status == "待贷款申请") {
        this.$router.push({ path: '/a-content/loan/reference-detail-main', query: { id: id, source: 'loanList' }})
      }
    },
    /*
    显示GPS单详情
     */
    showGpsDetail(id) {
      this.gpsOrderId=id
      this.newDialog=true
    },
    /*
    取消GPS单详情对话框，子组件回调
     */
    canceldialog(){
      this.newDialog = !this.newDialog;
    },
  }
}
</script>
